package com.flashmoment.video.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.flashmoment.video.utils.Constant;
import com.flashmoment.video.utils.PageUtils;
import com.flashmoment.video.utils.R;
import com.flashmoment.video.vo.UserCommentVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.flashmoment.video.entity.UserCommentEntity;
import com.flashmoment.video.service.UserCommentService;




/**
 * 用户评论表
 *
 * @author xulu
 * @email 1435533194@qq.com
 * @date 2023-10-24 16:35:33
 */
@RestController
@RequestMapping("video/usercomment")
@CrossOrigin
@Api(tags = "用户评论接口")
public class UserCommentController {
    @Autowired
    private UserCommentService userCommentService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userCommentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		UserCommentEntity userComment = userCommentService.getById(id);

        return R.ok().put("userComment", userComment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserCommentEntity userComment){
		userCommentService.save(userComment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserCommentEntity userComment){
		userCommentService.updateById(userComment);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		userCommentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @GetMapping("/findCommentByVideoId/{id}")
    public R findCommentByVideoId(@PathVariable("id")Integer id){
        List<UserCommentVo> commentVoList = userCommentService.findCommentByVideoId(id);
        if (commentVoList.isEmpty()){
            return R.ok().put("code", Constant.FAILURE_CODE).put("msg",Constant.SEARCH_FAILURE);
        }
        return R.ok().put("code",Constant.SUCCESS_CODE).put("commentVoList",commentVoList);
    }

}
